package com.test.practice.collection.list;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 10大坑
 *
 * @Description: 10大坑
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-03-15
 * =======================
 * @Version: 1.1.2.0
 */
public class ListBug {

    public static void main(String[] args) {


//        m1();
//
//        m1_1();
//
//        m1_2();


        String [] arr = {"1","2","3"};

        List<String> stringList = new ArrayList<>(Arrays.asList(arr));

        arr[2] = "4";

        System.out.println(stringList);

        Iterator<String> iterator = stringList.iterator();

        while (iterator.hasNext()) {
            if ("4".equals(iterator.next())) {
                iterator.remove();
            }
        }

        stringList.add("sss");
        stringList.remove("4");


        System.out.println(Arrays.asList(arr).toArray());

    }

    /**
     * 建数组的时候直接装箱
     */
    private static void m1_2() {
        Integer[] integerArr = {1, 2, 3};
        List<Integer> lists = Arrays.asList(integerArr);
        System.out.println(lists.size());
    }

    /**
     * 解决：利用Arrays.stream(arr).boxed()将其装箱为Integer数组
     */
    private static void m1_1() {
        int[] arr = {1, 2, 3};

        List<Integer> lists = Arrays
                .stream(arr)
                .boxed()
                .collect(Collectors.toList());

        System.out.println(lists);
        System.out.println(lists.get(0).getClass());
    }

    /**
     * 把 int数组 整体作为一个对象,返回了一个 值
     */
    private static void m1() {
        int[] arr = {1, 2, 3};

        List<int[]> lists = Arrays.asList(arr);

        System.out.println(lists.size());
        System.out.println(lists);
    }
}
